<?php

namespace Modules\Auth\Http\Controllers;

use Illuminate\Contracts\Support\Renderable;
use Modules\Auth\Http\Requests\UserLoginRequest;
use Modules\Auth\Http\Requests\AdminLoginRequest;
use Modules\Common\Http\Controllers\CommonController;
use Modules\Common\Services\CommonService;
use Modules\Auth\Entities\User;
use Modules\Auth\Entities\Admin;
class AuthController extends CommonController
{
    private $service;
    public function __construct(CommonService $service)
    {
        $this->service = $service;
    }
   public function userLogin(UserLoginRequest $request){
     $this->captchaApiCheck($request);
     $this->service->set(new User(),$request->all());
     $this->service->setGuzzleHttp('user');
     $result = $this->service->userLogin();
     return  $this->success($result);
   }
   public function adminLogin(AdminLoginRequest $request){
   // $this->captchaApiCheck($request);
    $this->service->set(new Admin(),$request->all());
    $this->service->setGuzzleHttp('admin');
       $result = $this->service->userLogin();
    return  $this->success($result);
  }
  public function captchaApiCheck($request){
    if (!captcha_api_check( $request->code, $request->key)){
      $this->fail('验证码错误');
   }
  }
  public function getCodeImage()
 {
     //输入二维码图片路径
     return $this->success(app('captcha')->create('default', true));
  }
}
